package tx.com.combat;

import android.graphics.Canvas;
import android.view.SurfaceHolder;

public class GameViewDrawThread extends Thread {
	boolean flag = true;
	int sleepSpan = 50;
	GameView gameView;
	SurfaceHolder holder;
	public GameViewDrawThread(GameView gameView){
		this.gameView = gameView;
		this.holder = gameView.getHolder();
	}
	
	public void run(){
		Canvas canvas;
		while(flag){
			canvas = null;
			try{
				canvas = this.holder.lockCanvas();
				synchronized(holder){
					gameView.onDraw(canvas);
				}
			}finally{
				if(canvas != null){
					holder.unlockCanvasAndPost(canvas);
				}
			}
			
			try{
				Thread.sleep(sleepSpan);
			}
			catch(Exception e){
				e.printStackTrace();
			}
		}
	}
	
	public void SetFlag(boolean flag){
		this.flag = flag;
	}
}